package fr.gest4team.app.pilotage.metier;

import java.util.Set;

import fr.gest4team.app.pilotage.dto.Activite;
import fr.gest4team.app.pilotage.dto.Planning;
import fr.gest4team.app.pilotage.dto.Tache;

/**
 * 
 * @author brug
 * 
 */
public class TacheOm extends Tache {

	private String nomVersion;

	/**
	 * universal id de la classe
	 */
	// static final long serialVersionUID = 0L;

	/**
	 * @param p
	 *            :
	 */
	@SuppressWarnings("unchecked")
	public void addPlanning(final PlanningOm p) {
		getPlannings().add(p);
	}

	/**
	 * @return Set<Planning>
	 */
	@Override
	@SuppressWarnings("unchecked")
	public Set getPlannings() {
		return super.getPlannings();
	}

	/**
	 * @param planningsParam
	 *            :
	 */
	@Override
	@SuppressWarnings("unchecked")
	public void setPlannings(final Set planningsParam) {
		super.setPlannings(planningsParam);
	}

	public float getConsommationDev() {
		float conso = 0;
		final Set<Planning> plannings = getPlannings();
		for (final Planning planning : plannings) {
			final Set<Activite> activites = planning.getActivites();
			for (final Activite activite : activites) {
				conso += activite.getTemps();
			}
		}
		return conso;
	}

	public float getChargePlanifieDev() {
		float charge = 0;
		final Set<Planning> plannings = getPlannings();
		for (final Planning pla : plannings) {
			charge += pla.getCharge();
		}
		return charge;
	}

	public float getRafDev() {
		float raf = 0;
		final Set<Planning> plannings = getPlannings();
		for (final Planning planning : plannings) {
			final float rafTache = getChargeDev() - planning.getCharge() + planning.getRaf();
			raf += rafTache;
		}
		return raf;
	}

	public float getEcartDev() {
		return getChargeDev() - getConsommationDev() - getRafDev();
	}

	public float getAvancementDev() {
		final float chargeDev = getChargeDev();
		final float rafDev = getRafDev();
		return (chargeDev != 0) ? ((chargeDev - rafDev) / chargeDev) * 100 : 0;
	}

	/**
	 * @return the nomVersion
	 */
	public String getNomVersion() {
		return nomVersion;
	}

	/**
	 * @param nomVersion
	 *            the nomVersion to set
	 */
	public void setNomVersion(final String nomVersion) {
		this.nomVersion = nomVersion;
	}
}
